package threadlocal;

import org.junit.Test;

/**
 * @author: zhangyi
 * @date: 2018/12/17 14:29
 * @description:
 */
public class ThreadLocalDemo {

    ThreadLocal threadLocal = new ThreadLocal();


    @Test
    public void demo(){
       for(int i = 10; i < 20; i++){
           int[] a = new int[]{i};
           new Thread(() -> {
               threadLocal.set(a[0]);
           }).start();
           new Thread(() -> {
               Integer integer = (Integer) threadLocal.get();
               System.out.println(integer+"-----------");
           }).start();
       }
        while(true){}
    }
}

class MyLocal{
    ThreadLocal<Object> threadLocal ;

    public MyLocal(ThreadLocal<Object> threadLocal) {
        this.threadLocal = threadLocal;
    }

    public void getDemo(){
        Object o = threadLocal.get();
        System.out.println(o);
    }
}